package com.syq.entity;

import java.util.List;

/**
 * @author wgy
 * @version V1.0
 * @project gp12_xiaomi
 * @package com.qf.entity
 * @description: ${TODO}
 * @date 2022/6/23 11:00
 */
public class PageBean<T> {
    //页码
    private int pageNum;
    //页大小
    private int pageSize;
    //总的数据个数
    private long totalSize;
    //总页数
    private int pageCount;
    //每页数据
    private List<T> data;
    //开始页码
    private int startPage;
    //结束页码
    private int endPage;

    public PageBean(int pageNum, int pageSize, long totalSize, List<T> data) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.totalSize = totalSize;
        this.data = data;
        //计算pageCount
        this.pageCount= (int) (totalSize%pageSize==0?totalSize/pageSize:totalSize/pageSize+1);

        //开始页码和结束页码
        //1 正常
        this.startPage=this.pageNum-4;
        this.endPage=this.pageNum+5;
        //2 查看后面
        if(this.pageNum>this.pageCount-5){
            this.startPage=this.pageCount-9;
            this.endPage=this.pageCount;
        }
        //3查看前面
        if(this.pageNum<5){
            this.startPage=1;
            this.endPage=10;
        }
        //4总页数不超过10页
        if(this.pageCount<10){
            this.startPage=1;
            this.endPage=this.pageCount;
        }
    }

    public PageBean() {
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getStartPage() {
        return startPage;
    }

    public void setStartPage(int startPage) {
        this.startPage = startPage;
    }

    public int getEndPage() {
        return endPage;
    }

    public void setEndPage(int endPage) {
        this.endPage = endPage;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", totalSize=" + totalSize +
                ", pageCount=" + pageCount +
                ", data=" + data +
                '}';
    }
}
